const arr = [1, 2, [3, 4, [5]], 6, { a: 7 }]


Array.prototype.myflat = function (num = 1) {
    let newArr = this
    while (this.some(item => Array.isArray[item])) {
        newArr = [].concat(...newArr) //  1, 2, 3, 4, 5, 6, { a: 7 } 
    }
}
const newArr = arr.flat(3)

console.log(newArr);